// 常用请求
var COMMON_URL = {
		//获取代码表, example实例：basePath + "/inner/getCodeDetail?code=T_DM_SEX&type=0"
		getCode: basePath + '/sys/inner/getCodeDetail',
		getMemCode: basePath + '/mem/mtype/getCodeDetail',
		getQTypeCode: basePath + '/cms/questype/getCodeDetail',
		getExamResult: basePath + '/cms/examrecord/getCodeDetail',
		getExecutePointCode: basePath + '/mem/pointexecutetype/getCodeDetail',
		getUserFunc: basePath + '/sys/resource!getUserFunc.action',
		uploadifySwf: basePath + '/static/plugin/uploadify/js/uploadify.swf',
//		newupload: 'http://192.168.199.72:8080/FileServer/newupload',
//		upload: 'http://192.168.199.72:8080/FileServer/upload',
		newupload: 'http://39.105.30.54/FileServer/newupload',
		upload: 'http://39.105.30.54/FileServer/upload',
		fileinfoadd: basePath + '/fileInfo/add',
		getFileInfos: basePath + '/fileInfo/getFileInfos',
		image: basePath + '/fileDownload/getImage',
		download: basePath + '/fileDownload/download',
		delFile: basePath + '/fileUpload/delFile',
		fileInfo: basePath + '/fileUpload/getFileInfo',
		showFile: basePath + '/fileDownload/initShowOffice',
};

var CommonUtil = {
	// 根据传入的权限标识,获取该菜单下的功能权限。
    getPermission: function (permit) {
    	if (top.globalPermission && top.globalPermission[permit]) {
    		return top.globalPermission[permit];
    	}
    	return [];
    },    
    //格式化日期
    formatDate: function(time) {
        var date = new Date(time),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate(),
            hours = date.getHours(),
            minutes = date.getMinutes(),
            seconds = date.getSeconds();
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    },
    //图片展示
    showImages : function (options){
        if ($("#imagesArea").length > 0){
            $("#imagesArea").empty();
        } else {
            $("body").append('<div id="imagesArea" style="display: none"></div>');
        }
        $.each(options.images,function(){
            $('<a>').attr({
                "href" : this.href,
                "data-lightbox" : this.group || "group1",
                "data-title": this.title || "默认"
            }).appendTo($("#imagesArea"));
        });
        if (options.defaultShow){
            $("#imagesArea a[data-title=" + options.defaultShow + "]").click();
        } else {
            $("#imagesArea a").first().click();
        }
    },

};

//######################################################################################




//######################################################################################




//去除开头结尾空格
function trimSpace(value) {
    if(value) {
        var reg = /(^\s+)|(\s+$)/g;
        if(reg.test(value)){
            value = $.trim(value);
        }
    }
    return value;
}

//防止在输入框内按enter键返回到主页面
document.onkeydown = check;
function check(e) {
    var ev = e || window.event,  //获取event对象
        obj = ev.target || ev.srcElement, //获取事件源
        t = obj.type || obj.getAttribute('type'), //获取事件源类型
        vReadOnly = obj.readOnly,  //只读
        vDisabled = obj.disabled;  //不可用

    //处理undefinde值
    vReadOnly = (vReadOnly == 'undefined') ? false : vReadOnly;
    vDisabled = (vDisabled == 'undefined') ? false : vDisabled;

    //当按backspace键时，事件类型为密码、单行、多行、文件类型时
    //并且readOnly为true或disabled为true时，退格失效
    var flag1 = (ev.keyCode == 8 &&(((t == "text" || t == "textarea" || t == "password") && (vReadOnly == true || vDisabled == true))  || t == "file"))
            || ((ev.ctrlKey) && ((ev.keyCode == 78) || (ev.keyCode == 82))) || // CtrlN,CtrlR
            (ev.keyCode == 116); //F5

    //当敲Backspace键时，事件源类型非密码或单行、多行文本、文件的，则退格键失效
    var flag2 = (ev.keyCode == 8 && t != "text" && t != "textarea" && t != "password" && t != "file")
    || ((ev.ctrlKey) && ((ev.keyCode == 78) || (ev.keyCode == 82))) || // CtrlN,CtrlR
    (ev.keyCode == 116);

    if (flag1 || flag2) {
        ev.returnValue = false;
        if (ev.preventDefault) {  //阻止默认行为(ie9以下不支持，要进行判断)
            ev.preventDefault();
        }
    }
}


